#include "unitmanagedialog.h"
#include "ui_unitmanagedialog.h"
#include "CommonInstanceSet1.h"
#include <QDebug>
#include <QWebFrame>
#include <QLibrary>
#include <QWebSettings>
#include <QWebSettings>

UnitManageDialog::UnitManageDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::UnitManageDialog)
{
    ui->setupUi(this);
#ifdef WIN32
    putenv("QTWEBKIT_PLUGIN_PATH=C:/css/plugins");
#else
    putenv("QTWEBKIT_PLUGIN_PATH=/usr/lib64/firefox/plugins");
#endif

#ifdef WIN32
    QLibrary lib("");
    lib.load();
#else
    QLibrary lib("/usr/lib64/firefox/plugins/libflashplayer.so");
    lib.load();
#endif

    QWebSettings *settings = QWebSettings::globalSettings();
    settings->setAttribute(QWebSettings::PluginsEnabled, true);//
    settings->setAttribute(QWebSettings::JavascriptEnabled, true);//JavaScript
    settings->setAttribute(QWebSettings::DeveloperExtrasEnabled, true);//
    settings->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);


}

UnitManageDialog::~UnitManageDialog()
{
    delete ui;
}

void UnitManageDialog::SetWebUrl(const QUrl &webUrl)
{
    ui->webView->load(webUrl);
}

void UnitManageDialog::ShowWeb(const int &deviceId)
{
    QString sManageStr;
    if (g_pCommonInstanceSet1 == NULL)
    {
        g_pCommonInstanceSet1 = new CommonInstanceSet1;
    }
    if (g_pCommonInstanceSet1->GetSysCfg() != NULL)
    {
        sManageStr = g_pCommonInstanceSet1->GetSysCfg()->GetManage();
    }

    QString url_str = sManageStr + QString("deviceId=%1&width=1000&height=680").arg(deviceId);
    qDebug() << url_str;
    ui->webView->load(QUrl(url_str));
    show();
}
